package movee.redis.lettuce.storage;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 调用redis低层接口，适配上层业务
 *
 * @author movee
 */
@Slf4j
@Component
public class RedisClient {

    private final StringRedisTemplate redisTemplate;

    @Autowired
    public RedisClient(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    //
    // region
    //
    public void addCnetRegion(String... regions) {
        redisTemplate.opsForSet().add(RedisKeys.cnetRegionsKey, regions);
    }

    public Set<String> getCnetRegion() {
        return redisTemplate.opsForSet().members(RedisKeys.cnetRegionsKey);
    }

    public Long remCnetRegionMember(String... regions) {
        return redisTemplate.opsForSet().remove(RedisKeys.cnetRegionsKey, regions);
    }

    public Boolean delCnetRegion() {
        return redisTemplate.delete(RedisKeys.cnetRegionsKey);
    }

}
